package com.forekenow.Demo4;

public class Master {
    private void cure(Pet pet){
        if (pet.getHealth()<50){
            pet.toHospital();
            System.out.println("吃药·······");
        }
    }
    private void feed(Pet pet){
        pet.eat();
    }

    public void play(Pet pet){
        if (pet instanceof Dog){
            Dog dog = (Dog) pet;
            dog.run();
        }

        if (pet instanceof Penguins){
            Penguins penguins = (Penguins) pet;
            penguins.swimming();
        }

    }

    public static void main(String[] args) {
        Master master = new Master();
        Pet p = new Dog();
        p.setName("卡卡");
        p.setHealth(20);
        p.setLove(99);
        master.cure(p);
        master.feed(p);
        master.play(p);

        p = new Penguins();
        p.setHealth(40);
        p.setLove(43);
        p.setName("花花");
        master.cure(p);
        master.feed(p);
    }
}
